package com.easyidea.its.util;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 从properties文件中获取信息
 * @author terry
 */
public class PropertiesUtil {
	
	private static  Map<String, String> I18N_REVERSE_MAP = new HashMap<String, String>();
	
	private static  Map<String, String> I18N_MAP = new HashMap<String, String>();
	
	private static Properties props;
	
//	static {
//		props = getProperties(TldConstants.AREA_PROPERTIES_PATH);
//		reverseKeyAndValue(props);
//		props = getProperties(TldConstants.ENUM_PROPERTIES_PATH);
//		reverseKeyAndValue(props);
//	}
	
	
	public static Properties getProperties(String propertiesPath){
		String currentPath = PropertiesUtil.class.getResource("/").getPath();
		Properties props = new Properties();
		try {
			props.load(new FileInputStream(currentPath + propertiesPath));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		return props;
	}
	
	
	public static void reverseKeyAndValue(Properties props){
		for (Enumeration e = props.keys() ; e.hasMoreElements() ;) {
		    String key = (String)e.nextElement();
		    String val = (String)props.get(key);
		    I18N_MAP.put(key, val);
		    I18N_REVERSE_MAP.put(val, key);
		}
	}
	
	
	public static Map<String, String> createI18nReverseMap(){
		
		return I18N_REVERSE_MAP;
	}
	
	
	public static Map<String, String> createI18nMap(){
		
		return I18N_MAP;
	}
	
	
}
